//package com.example.test;
//
//import com.aliyun.oss.*;
//import com.aliyun.oss.common.auth.DefaultCredentialProvider;
//import com.aliyun.oss.common.comm.SignVersion;
//import com.aliyun.oss.model.GetObjectRequest;
//
//import java.io.File;
//import java.net.URL;
//import java.util.Date;
//
//public class ClientDownload {
//    public static void main(String[] args) throws Exception {
//        // OSS访问域名。以华东1（杭州）地域为例，填写为https://oss-cn-hangzhou.aliyuncs.com。其它Region请按实际情况填写。
//        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
//// 从环境变量中获取步骤5生成的临时访问密钥AccessKey ID和AccessKey Secret，非阿里云账号AccessKey ID和AccessKey Secret。
//        String accessKeyId = "STS.NWXqQftfTohvfcQmPheWeEt1A";
//        String accessKeySecret = "6utGaeQ9srLeLvRY8et5kvd2RpitiiLq14xPyY62RUvm";
//// 从环境变量中获取步骤5生成的安全令牌SecurityToken。
//        String securityToken = "CAIS/AN1q6Ft5B2yfSjIr5TtOuvSmbl12KqdZEXgiVA9adhJqrGaozz2IHhMdXJoBegXsfQ+m25S5v4alqx9SoVeWRQ0uTiPXc4Fnzm6aq/t5uZMh95t0e9JcAr+Ihr/29CoLIedZdjBe/CrRknZnytou9XTfimjWFrXVv/sjoV8POwKQi6ybzdNGK1sRG1YpdQdKGHaONu0LxfumRCwNkdzvRdmgm4Nt8bPy8aHuB3Flw+4mK1Hv4ntOpytacRweYklMaW81/ckcbHagmwCqUpS+btuiKVC9CuCoIvaQSu9infrGu7Q9cIVY20dT6MmGqlCgeHhnPljwIL6nJj2zBA/WoMwVD/EFq+t3OzOGu6iKqwDF9DBNm/Kz8qEO7Tsrgogegh7Dg5RfMc7IXICV35cQzrBeKi84wKIMEXxU6WZyKU/15dpikuyn6iDLEPdRK6Cg2RKeM0kYl8wMxcQ0HCkbPVBMS40Kgs+XOrPHdspPUkG8fuz5je/DHMwkitl2NTlfO7Tt6wlboHyY4lLy4J1Zu4d6zN7FAyrE+Px2hZLKjY1Ge5Mu7HgJY9WLBIGezsdCASvKIfk2j0yGVi5x0IG2WrcjPFCyPeXyEtKiiXATZG9Yl5aan8KzPpxYy97n5gjAdJILQVcwepdXmGBNlLuyg4Snr98l9fRx846Fp/MGoABTvHhkG2wGdp+rU6Z6kU3I+uec3NKRCRXUwjgmHp0ODzFmq18X4fMO8WaFnFc1IuPEAv2lUXBG9PFKX7i07Goan/4eDdZntSBaOKmzi5Byi+n5OILkFmg9W3i33zG8s4XOj0SWhdzbleKu1Npl9OQRbgkNENaupuma+FKjXnMpoggAA==";
//        //        String objectName = "image/7/60609/1.jpg"; // 构造对象名
//        String objectName = "Avatar/6.jpg"; // 构造对象名
//        String pathName = "C:\\Users\\L\\Desktop\\avatar.png";
//        String bucketName="petplanet-v2";
//
//// 创建OSSClient实例。
//        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret, securityToken);
//
//
//
//
//        try {
//            // 下载Object到本地文件，并保存到指定的本地路径中。如果指定的本地文件存在会覆盖，不存在则新建。
//            // 如果未指定本地路径，则下载后的文件默认保存到示例程序所属项目对应本地路径中。
////            ossClient.getObject(new GetObjectRequest(bucketName, objectName), new File(pathName));
//            // 设置签名URL过期时间，单位为毫秒。本示例以设置过期时间为1小时为例。
//            Date expiration = new Date(new Date().getTime() + 3600 * 1000L);
//            // 生成以GET方法访问的签名URL。本示例没有额外请求头，其他人可以直接通过浏览器访问相关内容。
//            URL url = ossClient.generatePresignedUrl(bucketName, objectName, expiration);
//            System.out.println(url);
//
//        } catch (OSSException oe) {
//            System.out.println("Caught an OSSException, which means your request made it to OSS, "
//                    + "but was rejected with an error response for some reason.");
//            System.out.println("Error Message:" + oe.getErrorMessage());
//            System.out.println("Error Code:" + oe.getErrorCode());
//            System.out.println("Request ID:" + oe.getRequestId());
//            System.out.println("Host ID:" + oe.getHostId());
//        } catch (ClientException ce) {
//            System.out.println("Caught an ClientException, which means the client encountered "
//                    + "a serious internal problem while trying to communicate with OSS, "
//                    + "such as not being able to access the network.");
//            System.out.println("Error Message:" + ce.getMessage());
//        } finally {
//            if (ossClient != null) {
//                ossClient.shutdown();
//            }
//        }
//    }
//}
